package com.chinasofti.emp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.chinasofti.manager.service.EmpApplyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Creator: <br>
 * Date: <br>
 * Description: <br>
 */
@Controller
@RequestMapping("/emp/apply")
public class EmpApplyController {
    @Reference
    private EmpApplyService empApplyService;

    @GetMapping("/add")
    public ModelAndView add(){
        ModelAndView mv = new ModelAndView("apply/add");
        mv.addObject("depts", empApplyService.queryDepts());
        return mv;
    }

    @PostMapping("/add")
    public ModelAndView add(String name,
                            String targetDept){
        ModelAndView mv = new ModelAndView("apply/add");
        empApplyService.commitApply(name, targetDept);
        mv.addObject("msg", "已提交申请");
        return mv;
    }

}
